<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.cese.duss.ceseutil.CostUtil" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs3" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    out.print( "开始同步数据。。。。。。。" );
    String tablename = "formtable_main_469";
    rs.executeQuery( "select t.id,t.requestid,b.currentnodetype,t.yshd,t.sqrq,t.cblrzx,t.ywsqd from " + tablename + " t \n" +
            "left join workflow_requestbase b on t.requestid=b.requestid \n" +
            "where t.yshd is not null and b.currentnodetype>0" );
    int counts = rs.getCounts();
    out.print( "总记录数-------------counts=" + counts );
    int count = 0;
    String yslx = "";//状态
    while (rs.next()) {
        String mainid = Util.null2String( rs.getString( "id" ) );//mainid
        String requestid = Util.null2String( rs.getString( "requestid" ) );//mainid
        String ywsqd = Util.null2String( rs.getString( "ywsqd" ) );//业务申请单
        String yshd = Util.null2String( rs.getString( "yshd" ) );//预算活动
        String cblrzx = Util.null2String( rs.getString( "cblrzx" ) );//成本/利润中心
        String sqrq = Util.null2String( rs.getString( "sqrq" ) );//费用实际发生日期
        String currentnodetype = Util.null2String( rs.getString( "currentnodetype" ) );
        String currentDate = DateUtil.getCurrentDate();
        String newywsqd = CostUtil.getClsqdRequestid( ywsqd );
        if (!"1".equals( currentnodetype )) {  //0：创建
            yslx = "0";
            CostUtil.deleteYszxxxb( requestid );
            CostUtil.deleteYszxxxb( ywsqd );
            //明细3
            rs1.executeQuery( "select fykm,hdje from " + tablename + "_dt3 where mainid=?", mainid );
            while (rs1.next()) {
                String fykm = Util.null2String( rs1.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs1.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
            //明细4
            rs2.executeQuery( "select fykm,hdje from " + tablename + "_dt4 where mainid=?", mainid );
            while (rs2.next()) {
                String fykm = Util.null2String( rs2.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs2.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
            //明细5
            rs3.executeQuery( "select fykm,hdje from " + tablename + "_dt5 where mainid=?", mainid );
            while (rs3.next()) {
                String fykm = Util.null2String( rs3.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs3.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
        } else { // 3：归档
            yslx = "1";//发生
            CostUtil.deleteYszxxxb( requestid );
            CostUtil.deleteYszxxxb( ywsqd );
            //明细3
            rs1.executeQuery( "select fykm,hdje from " + tablename + "_dt3 where mainid=?", mainid );
            while (rs1.next()) {
                String fykm = Util.null2String( rs1.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs1.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
            //明细4
            rs2.executeQuery( "select fykm,hdje from " + tablename + "_dt4 where mainid=?", mainid );
            while (rs2.next()) {
                String fykm = Util.null2String( rs2.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs2.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
            //明细5
            rs3.executeQuery( "select fykm,hdje from " + tablename + "_dt5 where mainid=?", mainid );
            while (rs3.next()) {
                String fykm = Util.null2String( rs3.getString( "fykm" ) );//费用科目
                String hdje = Util.null2String( rs3.getString( "hdje" ) );//核对金额
                //费用报销信息更新到预算执行信息表
                CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, currentDate, hdje, yslx, currentDate );
            }
            //费用报销信息更新到预算执行表
            yslx = "2";//释放
            String sql2 = "update uf_yszxxxb set yslx=?,sfrq=? where lc=?";
            rs.executeUpdate( sql2, new Object[]{yslx, currentDate, newywsqd} );
            rs.writeLog( sql2, String.join( ",", yslx, currentDate, newywsqd ) );
        }
        count++;
    }
    out.print( "同步完成记录数------count" + count );
%>


